import request from '@api/request';
import { HttpUrl } from '@api/httpUrl';

// 获取所有客户订单列表
export function getOrderList(customerId: string, page: number, available: boolean, options: 'all' | 'true' | 'false') {
    return request.get<AjaxResponse['orderList']>(HttpUrl.getOrderList, { params: { customerId, page, available, options } });
}

// 使用客户id获取所有对应未发货订单列表
export function getAllUnDeliveryOrderListByCustomerId(customerId: string) {
    return request.get<AjaxResponse['orderList']>(HttpUrl.getAllUnDeliveryOrderListByCustomerId, { params: { customerId } });
}
// 通过订单号获取客户订单列表
export function getOrderListByOrderNo(orderNo: string) {
    return request.get<AjaxResponse['orderList']>(HttpUrl.getOrderListByOrderNo, { params: { orderNo } });
}

// 获取客户订单详情
export function getOrderDetail(id: string) {
    return request.get<AjaxResponse['orderList'][0]>(HttpUrl.getOrderDetail, { params: { id } });
}

// 获取未处理订单
export function getUnprocessedOrder() {
    return request.get<{
        unprocessedOrder: AjaxResponse['orderList'];
        unprocessedOrderTotal: number;
    }>(HttpUrl.getUnprocessedOrder);
}

// 获取所有未发货订单列表
export function getUnStatusOrder() {
    return request.get<{
        unStatusOrder: AjaxResponse['orderList'];
        unStatusOrderTotal: number;
    }>(HttpUrl.getUnStatusOrder);
}

// 创建单笔客户订单
export function createOrder(data: AjaxRequest['addOrderUseSystemForm']) {
    return request.post(HttpUrl.createOrder, { ...data });
}

// 更新客户订单
export function updateOrder(id: string, field: string, value: any) {
    return request.put(HttpUrl.updateOrder, { id, field, value });
}

// 删除订单时同步采购数据
export function deleteOrderSyncPurchase(orderNo: string) {
    return request.put(HttpUrl.deleteOrderSyncPurchase, { orderNo });
}

// 更新客户订单详情
export function updateOrderDetail(orderId: string, orderTax: boolean, orderAmount: number, data: AjaxResponse['orderList'][0]['orderDetail']) {
    return request.put(HttpUrl.updateOrderDetail, { orderId, orderTax, orderAmount, data });
}

// 更新客户送货日期
export function updateOrderDeliveryDate(orderNo: string, productNames: string[], deliveryDate: Date) {
    return request.put(HttpUrl.updateOrderDeliveryDate, { orderNo, productNames, deliveryDate });
}

// 订单处理回退
export function orderProcessBack(orderIds: string[]) {
    return request.put(HttpUrl.orderProcessBack, { orderIds });
}

// 订单完结回退
export function orderStatusBack(orderIds: string[]) {
    return request.put(HttpUrl.orderStatusBack, { orderIds });
}

// 删除客户订单
export function deleteOrder(ids: string[]) {
    return request.put(HttpUrl.deleteOrder, { ids });
}

// 删除订单文件
export function deleteOrderFile(orderId: string, index: number, type: string) {
    return request.post(HttpUrl.deleteOrderFile, { orderId, index, type });
}
